package liuwanghui.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import liuwanghui.common.Result;
import liuwanghui.dto.request.PasswordUpdateDTO;
import liuwanghui.dto.request.UserProfileUpdateDTO;
import liuwanghui.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@CrossOrigin
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Tag(name = "用户", description = "用户相关接口")
public class UserController {

    private final UserService userService;

    @GetMapping("/profile")
    @Operation(summary = "获取用户信息")
    public Result getProfile() {
        return userService.getProfile();
    }

    @PutMapping("/profile")
    @Operation(summary = "更新用户信息")
    public Result updateProfile(@RequestBody @Valid UserProfileUpdateDTO dto) {
        Long userId = userService.getCurrentUserId();
        return userService.updateProfile(userId, dto);
    }

    @PutMapping("/password")
    @Operation(summary = "修改密码")
    public Result updatePassword(@RequestBody @Valid PasswordUpdateDTO dto) {
        Long userId = userService.getCurrentUserId();
        return userService.updatePassword(userId, dto.getOldPassword(), dto.getNewPassword());
    }
} 